<template>
  <div class="content-div">
    <div class="login-win">
      <van-form @submit="onSubmit" input-align="right">
        <van-field
          class="login-input"
          v-model="form.name"
          label="就诊人姓名"
          placeholder="请输入就诊人姓名"
          :rules="[{ required: true, message: '请输入就诊人姓名' }]"
        />
        <van-field
          class="login-input"
          v-model="form.tel"
          label="手机号码"
          placeholder="请输入手机号码"
          :rules="[{ required: true, message: '请输入手机号码' }]"
        />
        <van-field
          class="login-input"
          v-model="form.address"
          label="收件地址"
          type="textarea"
          placeholder="请输入收件地址"
          :rules="[{ required: true, message: '请输入收件地址' }]"
        />
        <van-button class="login-btn" round block type="info" native-type="submit">保存</van-button>
      </van-form>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant'
import { insertAddress, getMemberAddress } from '@/api/medical.js'
export default {
  name: 'index',
  data () {
    return {
      form: {},
      id: ''
    }
  },
  created () {},
  methods: {
    onSubmit () {
      insertAddress({
        ...this.form,
        member_id: this.$store.state.user.token
      }).then(res => {
        if (res.data.errcode === 0) {
          Toast.success('保存成功')
          this.$router.go(-1)
        }
      })
    },
    getAddressInfo () {
      getMemberAddress({
        id: this.id
      }).then(res => {
        if (res.data.errcode === 0) {
          this.form = res.data.data
        }
      })
    }
  },
  mounted () {
    if (this.$route.query.id) {
      this.id = this.$route.query.id
      this.getAddressInfo()
    }
  }
}
</script>

<style scoped lang="less">
  .content-div{
    width: 100%;
    height: 100%;
    padding-top: 10px;
    box-sizing: border-box;
    background-color: #F8F8F8;
    font-size: 12px;
    .login-win{
      width: 300px;
      margin: 0 auto;
      background-color: #FFFFFF;
      border-radius: 10px;
      padding: 10px;
      box-sizing: border-box;
      .login-input{
        padding: 10px 4px;
      }
      /deep/.van-cell::after{
        left: 0;
        right: 0;
      }
      .login-btn{
        margin-top: 14px;
        height: 34px;
        line-height: 34px;
        border-radius: 10px;
      }
      /deep/.van-field__control, /deep/.van-field__error-message{
        font-size: 12px;
      }
      /deep/ .van-field__label{
        font-size: 12px;
      }
      // /deep/.van-cell::after{
      //   display: none;
      // }
      /deep/ .van-radio{
        margin-right: 0;
        margin-left: 10px;
      }
    }
  }
</style>
